package com.burgess.net.config.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * AOP使用示例
 */
@Configuration
@Aspect
public class AopConfig {

    @Around("@within(org.springframework.stereotype.Controller)")
    public Object simpleAop(final ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        try{
            Object[] args = proceedingJoinPoint.getArgs();
            System.out.println("args:" + Arrays.asList(args));
            //调用原有方法
            Object proceed = proceedingJoinPoint.proceed();
            System.out.println("return:" +proceed);
            return proceed;
        }catch (Throwable e){
            throw e;
        }
    }

}
